import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import 'common/public.css'; /*引入公共样式*/   

Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App
})
// let baseUrl = "https://a5942g1060.zicp.fun/huajia-backend"
let baseUrl = "http://10.66.128.40:8081/huajia-backend"
Vue.prototype.url = {
	register: baseUrl + "/user/register",
	login: baseUrl + "/user/login",
	searchAllActivityByPage: baseUrl + "/activity/searchAllActivityByPage",
	searchActivityContentById: baseUrl + "/activity/searchActivityContentById",
	insertActivity: baseUrl + "/activity/insertActivity",
	updateActivityEnrollment: baseUrl + "/activity/updateActivityEnrollment",
	searchMyPublishByPage: baseUrl + "/activity/searchMyPublishByPage",
	searchMyParticipationByPage: baseUrl + "/activity/searchMyParticipationByPage",
	refreshMessage: baseUrl + "/message/refreshMessage",
	searchMessageByPage: baseUrl + "/message/searchMessageByPage",
	searchMessageById: baseUrl + "/message/searchMessageById",
	updateUnreadMessage: baseUrl + "/message/updateUnreadMessage", 
	deleteMessageRefById: baseUrl + "/message/deleteMessageRefById",
	searchUserById: baseUrl + "/user/searchUserById",
	updateUserInfo: baseUrl + "/user/updateUserInfo",
	searchUserSummary: baseUrl + "/user/searchUserSummary",
	searchAllProductByPage: baseUrl + "/product/searchAllProductByPage",
	insertAddressInfo: baseUrl + "/info/insertAddressInfo",
	searchUserAddressInfo: baseUrl + "/info/searchUserAddressInfo",
	deleteAddressInfo: baseUrl + "/info/deleteAddressInfo",
	insertOrder: baseUrl + "/order/insertOrder",
	searchUserPoint: baseUrl + "/user/searchUserPoint",
	updateAddressInfo: baseUrl + "/info/updateAddressInfo",
	sendMessage: baseUrl + "/chat/sendMessage",
	getMessage: baseUrl + "/chat/getMessage",
	getAcceptId: baseUrl + "/chat/getAcceptId",
	haveNew: baseUrl + "/chat/haveNew",
	isFinished: baseUrl + "/activity/isFinished",
	checkIn: baseUrl + "/activity/checkIn",
	searchMyOrder: baseUrl + "/order/searchMyOrder",
	searchCityWide: baseUrl + "/dynamic/searchCityWide",
	insertDynamic: baseUrl + "/dynamic/insertDynamic",
	searchMyDynamic: baseUrl + "/dynamic/searchMyDynamic",
	searchDynamic: baseUrl + "/dynamic/searchDynamic",
	detail: baseUrl + "/dynamic/detail",
	getComments: baseUrl + "/dynamic/getComments",
	addComment: baseUrl + "/dynamic/addComment",
	insertComment: baseUrl + "/dynamic/insertComment",
	searchHotDynamic: baseUrl + "/dynamic/searchHotDynamic",
	giveThumbs: baseUrl + "/dynamic/giveThumbs",
	giveCommentThumbs: baseUrl + "/dynamic/giveCommentThumbs",
	getHotComments: baseUrl + "/dynamic/getHotComments",
}

Vue.prototype.ajax = function(url, method, data, fun){
	uni.request({
		"url": url,
		"method": method,
		"header": {
			token: uni.getStorageSync('token')
		},
		"data": data,
		success:function(resp){
			if(resp.statusCode == 401){
				uni.redirectTo({
					url:'../login/login'
				});
			}else if (resp.statusCode == 200 && resp.data.code == 200){
				let data = resp.data
				console.log(data)
				if(data.hasOwnProperty('token')){
					let token = data.token
					uni.setStorageSync("token", token)
				}
				fun(resp)
			}else{
				uni.showToast({
					icon:'none',
					title: resp.data
				});
			}
		}
	});
}
Vue.prototype.checkPermission = function(perms){
	let permission = uni.getStorageSync("permission")
	let result = false;
	for(let one of perms){
		if(permission.indexOf(one) != -1){
			result = true;
			break;
		}
	}
	return result;
}
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif

Date.prototype.format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"h+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		}
	}
	return fmt;
}
Vue.prototype.checkNull = function(data, name) {
	if (data == null) {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	}
	return false
}
Vue.prototype.checkBlank = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidName = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^[\u4e00-\u9fa5]{2,15}$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidTel = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^1[0-9]{10}$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidEmail = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidStartAndEnd = function(start, end) {
	let d1 = new Date("2000/01/01 " + start + ":00");
	let d2 = new Date("2000/01/01 " + end + ":00");
	if (d2.getTime() <= d1.getTime()) {
		uni.showToast({
			icon: "none",
			title: "结束时间必须大于开始时间"
		})
		return true
	}
	return false
}